import Vue from 'vue'
import Router from 'vue-router'
import login from '@/view/login'
import home from '@/view/home'
import delivery from '@/component/SaleManage/delivery'
import AddShipment from '@/component/SaleManage/AddShipment'
import returnGoods from '@/component/SaleManage/returnGoods'
import error from '@/component/error/error'
import index from '@/component/index/index'
import outsourcing from '@/component/warehousingManage/outsourcing'
import warehousing from '@/component/warehouseManage/warehousing'
import Addoutsourcing from '@/component//WarehousingManage/Addoutsourcing'
import outsourcingOut from '@/component/OutboundManage/OutsourcingOut'
import Editoutsourcing from '@/component/OutboundManage/Editoutsourcing'
import InventoryDetails from '@/component/StatisticalManage/InventoryDetails'
import { GetCookie } from '../api/storage'
Vue.use(Router)

const routers = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path: "/view",
      name: "home",
      component: home,
      redirect: "/view/index/index",
      children: [
        {
          path: "index/index",
          name: "index",
          component: index,
        },
        {
          path: "SaleManage/delivery",
          name: "delivery",
          component: delivery,
        },
        {
          path: "SaleManage/AddShipment",
          name: "AddShipment",
          component: AddShipment,
        },
        {
          path: "SaleManage/returnGoods",
          name: "returnGoods",
          component: returnGoods,
        },
        {
          path: "WarehousingManage/outsourcing",
          name: "outsourcing",
          component: outsourcing,
        },
        {
          path: "OutboundManage/OutsourcingOut",
          name: "outsourcingOut",
          component: outsourcingOut,
        },
        {
          path: "OutboundManage/Editoutsourcing",
          name: "Editoutsourcing",
          component: Editoutsourcing,
        },
        {
          path: "WarehousingManage/Addoutsourcing",
          name: "Addoutsourcing",
          component: Addoutsourcing,
        },
        {
          path: "WarehouseManage/warehousing",
          name: "warehousing",
          component: warehousing,
        },
        {
          path: "WarehouseManage/InventoryDetails",
          name: "InventoryDetails",
          component: InventoryDetails,
          meta: {
            requireAuth: true // 添加需要权限的标记
          }
        }
      ]
    },
    // {
    // path: '*',
    // name: 'error',
    // component: error,
    // }
  ]
})
routers.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (GetCookie("uid") * 1 == 0) {
      next()
    } else {
      alert("抱歉的，没有访问权限")
      next({ name: from.name })
    }
  }
  else {
    next()
  }
})
export default routers
